﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.views.popups.missions {
    import reprise.ui.*;
    import flash.events.*;
    import flash.display.*;
    import reprise.controls.*;
    import net.wooga.pets.events.*;
    import net.wooga.pets.models.world.vos.*;
    import net.wooga.pets.models.*;
    import net.wooga.pets.constants.*;
    import net.wooga.pets.utils.*;
    import net.wooga.pets.models.fountain.*;

    public class MissionTasksPopupMediator extends AbstractMissionPopupMediator {

        public var tutorialModel:TutorialModel;
        public var symbolModel:SymbolModel;
        public var userModel:UserModel;
        public var inventoryModel:InventoryModel;
        public var levelModel:LevelModel;

        override protected function setContent():void{
            var _local4:TaskVO;
            if (_mission.isLevelMission){
                _speakerLinkage = "Missions_Karla";
            };
            var _local1:UIComponent = RepriseUtils.addComponent(this.view, "tasksContent");
            var _local2:Array = _mission.tasks;
            var _local3 = 1;
            for each (_local4 in _local2) {
                var _temp1 = _local3;
                _local3 = (_local3 + 1);
                this.setTask(_temp1, _local4, _local1);
            };
            if (this.tutorialModel.state <= TutorialModel.ROOMTUTORIAL_FINISH_TUTORIAL){
                closeButton.hide();
            };
            super.setContent();
        }
        override protected function onGive(_arg1:MouseEvent):void{
            super.onGive(_arg1);
            var _local2:TaskVO = (_arg1.currentTarget as LabelButton).data();
            dispatch(new InfoEvent(EventConstants.PERFORM_TASK, _local2.id, _local2));
            close();
        }
        protected function setTask(_arg1:int, _arg2:TaskVO, _arg3:UIComponent):void{
            var _local14:int;
            var _local15:Boolean;
            var _local4 = (_arg2.action == GameConstants.SEND_MAYOR);
            var _local5:UIComponent = RepriseUtils.addComponent(_arg3, "missionTask");
            var _local6:String = getTaskThumb(_arg2);
            var _local7:MovieClip = getTaskIcon(_local6);
            var _local8:MovieClip = AssetsLibrary.getMovieClip("TaskIconHolder");
            if (_local7){
                _local7.gotoAndStop("default");
                _local8.icon.addChild(_local7);
                Displays.correctScaling(_local8.icon, _local7, 45, 45);
            };
            var _local9:UIComponent = RepriseUtils.addClipComponent(_local5, "taskIcon", _local8);
            var _local10 = (((("mission_" + _mission.code) + "_task") + _arg1) + "_");
            var _local11:int = this.getRequiredLevelForType(_arg2.action, _arg2.type);
            var _local12:String = getPetName(_arg2.type);
            this.addHint((_local10 + "hint"), _local11, _local9);
            addLabel("taskHeader myriadProFontOutline", (_local10 + "title"), {amount:_arg2.required, pet:_local12}, _local9);
            var _local13:String = (_arg2.isFinished) ? "taskCheckbox solved" : "taskCheckbox";
            if (_local4){
                if (_arg2.isFinished){
                    RepriseUtils.addComponent(_local9, _local13);
                } else {
                    _local14 = this.getActualItemCount(_arg2);
                    _local15 = (_local14 >= _arg2.required);
                    addGiveButton(_arg2, _local15, _local5);
                };
            } else {
                RepriseUtils.addComponent(_local9, _local13);
                addLabel("taskCount myriadProFontOutline", "global_of", {has:_arg2.current, needed:_arg2.required}, _local9);
            };
            if ((((_arg2.action == GameConstants.RECEIVE_A_GIFT)) && (!(_arg2.isFinished)))){
                this.addRequestButton(_local5, _arg2.type);
            };
        }
        protected function addHint(_arg1:String, _arg2:int, _arg3:UIComponent):void{
            addLabel("taskBody myriadProFont", _arg1, {amount:_arg2}, _arg3);
        }
        private function getRequiredLevelForType(_arg1:String, _arg2:String):int{
            var _local3 = -1;
            switch (_arg1){
                case GameConstants.PLACE_ROOM:
                    _local3 = this.levelModel.getLevelOfRoomType(_arg2);
                    break;
                case GameConstants.CURE_PET:
                    break;
            };
            return (_local3);
        }
        private function getActualItemCount(_arg1:TaskVO):int{
            var _local2:int;
            var _local3:String = _arg1.type.toLowerCase();
            switch (_local3){
                case GameConstants.USER_DATA_GOODS:
                    _local2 = this.userModel.goods;
                    break;
                case GameConstants.COINS:
                    _local2 = this.userModel.coins;
                    break;
                case GameConstants.COFFEE.toLowerCase():
                    _local2 = this.userModel.coffee;
                    break;
                case GameConstants.LOVE:
                case GameConstants.FIRE:
                case GameConstants.WATER:
                case GameConstants.AIR:
                case GameConstants.STAR:
                case GameConstants.ICE:
                    _local2 = this.symbolModel.symbols[_local3];
                    break;
                default:
                    _local2 = this.inventoryModel.getItemNumberByKey(("Reward" + _arg1.type));
                    break;
            };
            return (_local2);
        }
        private function addRequestButton(_arg1:UIComponent, _arg2:String):void{
            var _local3:LabelButton = createButton(_arg1, "askButton greenButton", "global_button_ask", "myriadProFont");
            _local3.setData({typeId:_arg2});
            eventMap.mapListener(_local3, MouseEvent.CLICK, this.onAskClick);
        }
        private function onAskClick(_arg1:MouseEvent):void{
            var _local2:LabelButton = (_arg1.target as LabelButton);
            var _local3:String = _local2.data().typeId;
            var _local4:InfoEvent = new InfoEvent(GameConstants.ASK_FOR_SYMBOL, _local3);
            dispatch(_local4);
        }
        protected function get view():MissionTasksPopupView{
            return ((viewComponent as MissionTasksPopupView));
        }

    }
}//package net.wooga.pets.views.popups.missions 
